package com.earthea.scaffold.system.controller;

import com.earthea.scaffold.common.aop.annotation.ControllerLog;
import com.earthea.scaffold.common.entity.BaseCollectionRsp;
import com.earthea.scaffold.common.enums.OperateTypeEnum;
import com.earthea.scaffold.common.util.ExcelUtil;
import com.earthea.scaffold.domain.DictData;
import com.earthea.scaffold.system.service.DictDataService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 数据字典信息
 */
@RestController
@RequestMapping("/api/system/dict/data")
public class DictDataController {
    @Autowired
    private DictDataService dictDataService;

    @GetMapping()
    public BaseCollectionRsp<DictData> list(DictData dictData) {
        return dictDataService.select(dictData);
    }

    @ControllerLog(title = "字典数据导出", operateType = OperateTypeEnum.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DictData dictData) {
        BaseCollectionRsp<DictData> list = dictDataService.select(dictData);
        ExcelUtil.export(response, "字典数据", list.getRows(), DictData.class);
    }

}
